import axios from 'axios'
import { ElMessage } from 'element-plus'
// const baseURL = import.meta.env["VITE_BASE_API"]

const request = axios.create({
  //第一个api用于代理，第二个api是后端接口前缀
  baseURL: '',
  timeout: 20000
})

request.interceptors.request.use((config) => {
  return config

}, (error) => {
  return Promise.reject(error)
})

request.interceptors.response.use(async (response) => {
  if (response.data.status) {
    ElMessage.success(response.data.message)
    return response.data
  } else {
    ElMessage.error(response.data.message)
    return Promise.reject(response.data)
  }

}, (error) => {
  return Promise.reject(error)
})
export default request
